<?php

namespace app\api\model\user;

use app\api\model\Models;

class UserInfo extends Models
{

    /*
     * 定义全局的查询范围
     * @var array
     */
    protected $globalScope = ['uid'];

    /**
     * 设置新增数据自动填充
     * @var array
     */
    protected $insert = ['uid'];

    /**
     * 根据用户获取收藏
     * @param \think\db\Query $query
     * @return void
     */
    public function scopeUid( \think\db\Query $query )
    {
        $query->where('uid', app('request')->userInfo['id']);
    }

    /**
     * 设置uid自动存储
     *
     * @return mixed
     */
    protected function setUidAttr()
    {
        return app('request')->userInfo['id'];
    }
}
